package com.yixiu.study.juc.queue;

import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @CalssName T03_ArrayBlockingQueue
 * @Description
 * @Author yixiu
 * @Date 2021/6/29 9:43
 * @Verison 1.0
 **/
public class T03_ArrayBlockingQueue {

    static BlockingQueue<String> strs = new ArrayBlockingQueue<>(10);

    static Random r = new Random();

    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i < 10; i++) {
            strs.put("a" + i);
        }

        //满了就会等待，程序阻塞
//        strs.put("aaa");
        //满了就会抛异常 Queue full
//        strs.add("aaa");
        //是否添加成功会返回boolean值
//        System.out.println(strs.offer("aaa"));

        System.out.println(strs.offer("aaa", 10, TimeUnit.SECONDS));

        System.out.println(strs);

    }


}
